package service

import (
	"RocFamilySystem/internal/repository"
	"RocFamilySystem/models"
)

type SysCacheService struct {
	SysCacheRepository *repository.SysCacheRepository
}

// 初始化
func init() {
	registerContainer["SysCacheService"] = &SysCacheService{}
}

// SetRepository 设置持久层
func (service *SysCacheService) SetRepository(sysCacheRepository *repository.SysCacheRepository) {
	service.SysCacheRepository = sysCacheRepository
}

// AddSysCache 添加系统缓存
func (service *SysCacheService) AddSysCache(sysCache *models.SysCache) {
	service.SysCacheRepository.InsertSysCache(sysCache)
}

// RemoveSysCache 删除系统缓存
func (service *SysCacheService) RemoveSysCache(sysCacheId int) {
	service.SysCacheRepository.DeleteSysCache(sysCacheId)
}

// RemoveSysCacheBatch 批量删除系统缓存
func (service *SysCacheService) RemoveSysCacheBatch(ids []string) {
	service.SysCacheRepository.DeleteSysCacheBatch(ids)
}

// ModifySysCache 修改系统缓存
func (service *SysCacheService) ModifySysCache(sysCache *models.SysCache) {
	service.SysCacheRepository.UpdateSysCache(sysCache)
}

// QuerySysCache 查询系统缓存
func (service *SysCacheService) QuerySysCache(pageNum, pageSize int) PageInfo {
	tables, total := service.SysCacheRepository.SelectSysCache(pageNum, pageSize)
	return toPageInfo(pageNum, pageSize, total, tables)
}

// QuerySysCacheAll 查询所有系统缓存
func (service *SysCacheService) QuerySysCacheAll() []models.SysCache {
	tables := service.SysCacheRepository.SelectSysCacheAll()
	return tables
}

// QuerySysCacheById 通过ID查询系统缓存
func (service *SysCacheService) QuerySysCacheById(id int) models.SysCache {
	return service.SysCacheRepository.SelectSysCacheById(id)
}
